package com.emperor.controller.vmservice;

import com.emperor.dto.ApplyPolicyRequestDto;
import com.emperor.dto.TbVmTypeDto;
import com.emperor.dto.UpdateChannelRequestDto;
import com.emperor.dto.VmTypeDto;
import com.emperor.entity.VmType;
import com.emperor.result.Result;
import com.emperor.service.VmService;
import com.emperor.vo.BusinessTop10Vo;
import com.emperor.vo.ChannelListVo;
import com.emperor.vo.VmTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("vmServiceVmType")
@RequestMapping("/vm-service")
@Api(tags = "售货机类型列表")
public class VmController {

    @Autowired
    private VmService vmService;

    @GetMapping("/vmType/search")
    public Result<VmType> findAllVm(VmTypeDto vmTypeDto) {
        VmType vmType = vmService.findVmType(vmTypeDto);
        return Result.success(vmType);
    }

    @GetMapping("/channel/channelList/{innerCode}")
    public Result<List<ChannelListVo>> findChannelList(@PathVariable String innerCode) {
        List<ChannelListVo> list = vmService.findChannelList(innerCode);
        return Result.success(list);
    }

    /**
     * 新增售货机
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增售货机")
    @PostMapping("/vm")
    public Result<VmTypeVo> addVm(@RequestBody TbVmTypeDto dto) {
        VmTypeVo vo = vmService.addVm(dto);
        return Result.success(vo);
    }

    /**
     * 修改售货机点位
     *
     * @param id
     * @param nodeId
     * @return
     */
    @ApiOperation("修改售货机点位")
    @PutMapping("/vm/{id}/{nodeId}")
    public Result updateVm(@PathVariable Integer id, @PathVariable Integer nodeId) {
        vmService.updateVm(id, nodeId);
        return Result.success();
    }

    /**
     * 获取商圈下销量前10的商品(补货推荐)
     *
     * @param businessId
     * @return
     */
    @ApiOperation("获取商圈下销量前10的商品(补货推荐)")
    @GetMapping("/sku/businessTop10/{businessId}")
    public Result<List<BusinessTop10Vo>> businessTop10(@PathVariable Integer businessId) {
        List<BusinessTop10Vo> vo = vmService.businessTop10(businessId);
        return Result.success(vo);
    }
    @ApiOperation("货道配置")
    @PutMapping("/channel/channelConfig")
    public Result channelConfig(@RequestBody UpdateChannelRequestDto dto) {
        vmService.channelConfig(dto);
        return Result.success();
    }
    @ApiOperation("应用策略")
    @PutMapping("/vm/applyPolicy")
   public Result applyPolicy(@RequestBody ApplyPolicyRequestDto dto) {
      vmService.applyPolicy(dto);
        return Result.success();
    }

}
